import pandas as pd
import matplotlib.pyplot as plt
import os
import sys

# 获取当前脚本的完整路径
script_path = os.path.abspath(sys.argv[0])
# 从完整路径中获取目录
script_dir = os.path.dirname(script_path)
# 从完整路径中分离出文件名
script_name = os.path.basename(script_path)
# 使用 splitext() 函数分离文件名和扩展名
script_name_without_extension, _ = os.path.splitext(script_name)

# 创建保存图像的完整路径
save_path = os.path.join(script_dir, script_name_without_extension + ".png")


# Import Data
df = pd.read_csv("https://raw.githubusercontent.com/selva86/datasets/master/mpg_ggplot2.csv")
df_counts = df.groupby(['hwy', 'cty']).size().reset_index(name='counts')

# Map counts to a suitable range for size of scatter plot points
sizes = (df_counts['counts']*50).values

# Scatter plot
fig, ax = plt.subplots(figsize=(16,10), dpi= 80)    
scatter = ax.scatter(df_counts.cty, df_counts.hwy, s=sizes)
  
# Decorations
plt.title('Counts Plot - Size of circle is bigger as more points overlap', fontsize=22)
plt.savefig(save_path, dpi=300)
plt.show()
